package ar.com.photo_admin.domain


class PhotoInAlbum {
	
	EventPhoto photo
	EventAlbum album
	
	static belongsTo = [photo:EventPhoto, album:EventAlbum]
	
    static constraints = {
    }
	
	static PhotoInAlbum link(photo, album) { 
		def m = PhotoInAlbum.findByPhotoAndAlbum(photo, album) 
		if (!m) { 
			m = new PhotoInAlbum() 
			photo?.addToPhotoInAlbums(m)
			album?.addToPhotoInAlbums(m) 
			m.save() 
		} 
		
		return m 
	}
	
	static void unlink(photo, album) { 
		def m = PhotoInAlbum.findByPhotoAndAlbum(photo, album) 
		if (m) { 
			photo?.removeFromPhotoInAlbums(m)
			album?.removeFromPhotoInAlbums(m) 
			m.delete() 
		} 
		
	}
}
